package com.vincent.kdp.ui.fragment.presenter;

import android.content.Intent;

import com.vincent.baseapp.base.BasePresenter;
import com.vincent.baseapp.util.SPUtil;
import com.vincent.kdp.bean.MyBanner;
import com.vincent.kdp.http.RequestCallBack;
import com.vincent.kdp.ui.bean.response.BaseOutput;
import com.vincent.kdp.ui.bean.response.HotCommodityListOutput;
import com.vincent.kdp.ui.bean.response.ShopCartListOut;
import com.vincent.kdp.ui.fragment.contract.ShopCartContract;
import com.vincent.kdp.ui.fragment.repository.CommodityRepository;
import com.vincent.kdp.ui.fragment.repository.NewRepository;
import com.vincent.kdp.ui.fragment.repository.ShopCartRepository;
import com.vincent.kdp.util.RegexUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/22 0022.
 */

public class ShopCartPresenter extends BasePresenter<ShopCartContract.View> implements ShopCartContract.Presenter{

    private List<String> mBannerList;//列表
    private ShopCartRepository mRepository;


    public ShopCartPresenter() {
        mRepository = new ShopCartRepository();

        mBannerList = new ArrayList<>();


    }
    @Override
    public void initView(Intent intent) {
        reqShopCartList();
    }

    public void dellist(String ids) {
        reqClearShopCartList(ids);
    }

    /**
     * 获取购物车列表
     */
    public void reqShopCartList() {
        mView.showLoadDialog();
        mRepository.reqShopCartList(new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                ShopCartListOut ShopCartListOutput = (ShopCartListOut) object;
                if (mView != null) {
                    mView.dismissLoadDialog();
                    if (ShopCartListOutput.getData() != null) {
                        mView.initShopCartList(ShopCartListOutput.getData());
                    }
                }
            }

            @Override
            public void onFalse(String msg) {
                if (mView != null) {
                    mView.dismissLoadDialog();
                    mView.showToast(msg);
                }
            }
        });
    }
    /**
     * 清空购物车列表
     */
    public void reqClearShopCartList(String ids) {
        mRepository.reqClearCartList(ids,new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                BaseOutput hotCommodityListOutput = (BaseOutput) object;
                if (mView != null) {
                    mView.dismissLoadDialog();
                    if (hotCommodityListOutput.getCode()==0) {
                        mView.relist();
                    }
                }
            }

            @Override
            public void onFalse(String msg) {
                if (mView != null) {
                    //mView.dismissLoadDialog();
                    //mView.showToast(msg);
                }
            }
        });
    }

    /**
     * 购买
     */
    private void reqShopCartList3() {
        mView.showLoadDialog();
        mRepository.reqShopCartList(new RequestCallBack() {
            @Override
            public void onSuccess(Object object) {
                HotCommodityListOutput hotCommodityListOutput = (HotCommodityListOutput) object;
                if (mView != null) {
                    mView.dismissLoadDialog();
                    if (hotCommodityListOutput.getData() != null) {
                        // mView.initHotCommodities(hotCommodityListOutput.getData());
                    }
                }
            }

            @Override
            public void onFalse(String msg) {
                if (mView != null) {
                    //mView.dismissLoadDialog();
                    //mView.showToast(msg);
                }
            }
        });
    }
}
